package com.cfcc.deptone.assetbarcodemgr.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.cfcc.deptone.assetbarcodemgr.R;
import com.cfcc.deptone.assetbarcodemgr.constant.AssetConstants;
import com.cfcc.deptone.assetbarcodemgr.entity.Product;
import com.cfcc.deptone.assetbarcodemgr.utils.PandianFileUtils;

import java.io.File;

public class AssetModifyActivity extends AppCompatActivity {

	private TextView codeModifyTv;
	private EditText addressModifyEt;
	private EditText productNameModifyEt;
	private EditText buildAreaModifyEt;
	private EditText brandModifyEt;
	private EditText modelModifyEt;
	private EditText passportNoModifyEt;
	private EditText productNoModifyEt;
	private EditText pandianFlgModifyEt;
	private EditText pandianDateModifyEt;
	private EditText assettypeModifyEt;
	private EditText remarkModifyEt;

	private Button applyModifyBtn;
	private Button cancelModifyBtn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_asset_modify);
		
		codeModifyTv = (TextView) findViewById(R.id.code_modify_tv);
		addressModifyEt = (EditText) findViewById(R.id.adress_modify_et);
		productNameModifyEt = (EditText) findViewById(R.id.asset_modify_et);
		buildAreaModifyEt = (EditText) findViewById(R.id.buildarea_modify_et);
		brandModifyEt = (EditText) findViewById(R.id.brand_modify_et);
		modelModifyEt = (EditText) findViewById(R.id.model_modify_et);
		passportNoModifyEt = (EditText) findViewById(R.id.passport_modify_et);
		productNoModifyEt = (EditText) findViewById(R.id.productno_modify_et);
		pandianFlgModifyEt = (EditText) findViewById(R.id.ispandian_modify_et);
		pandianDateModifyEt = (EditText) findViewById(R.id.pandian_date_modify_et);
		assettypeModifyEt = (EditText) findViewById(R.id.assettype_modify_et);
		remarkModifyEt = (EditText) findViewById(R.id.remark_modify_et);

		applyModifyBtn = (Button) findViewById(R.id.apply_modify_btn);
		cancelModifyBtn = (Button) findViewById(R.id.cancel_modify_btn);
		
		final Product product = new Product();
		
		Intent intent = getIntent();
		final Bundle bundle = intent.getExtras();
		
		int pos = bundle.getInt(AssetConstants.PRODUCT_COLNAME_POS);
		product.setPos(pos);
		
		String item = bundle.getString(AssetConstants.PRODUCT_COLNAME_BARCODE);
		codeModifyTv.setText(item.trim());
		product.setBarCode(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_PRODUCTNAME);
		productNameModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_ADDRESS);
		addressModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_BUILDAREA);
		buildAreaModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_BRAND);
		brandModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_MODEL);
		modelModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_PASSPORTNO);
		passportNoModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_PRODUCTNO);
		productNoModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_PANDIANFLG);
		pandianFlgModifyEt.setText(item.trim());
		
		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_PANDIANDATE);
		pandianDateModifyEt.setText(item.trim());

		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_ASSETTYPE);
		assettypeModifyEt.setText(item.trim());

		item = bundle.getString(AssetConstants.PRODUCT_COLNAME_REMARK);
		remarkModifyEt.setText(item.trim());
		
		applyModifyBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				product.setProductName(productNameModifyEt.getText().toString().trim());
				product.setAddress(addressModifyEt.getText().toString().trim());
				product.setBuildArea(buildAreaModifyEt.getText().toString().trim());
				product.setBrand(brandModifyEt.getText().toString().trim());
				product.setModel(modelModifyEt.getText().toString().trim());
				product.setPassportNo(passportNoModifyEt.getText().toString().trim());
				product.setProductNo(productNoModifyEt.getText().toString().trim());
				product.setCheckinStatus(pandianFlgModifyEt.getText().toString().trim());
				product.setPandianDate(pandianDateModifyEt.getText().toString().trim());
				product.setAssetType(assettypeModifyEt.getText().toString().trim());
				product.setRemarks(remarkModifyEt.getText().toString().trim());
				PandianFileUtils.modifyByRandom(product, getFilePath());
			}
		});
		
		cancelModifyBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		
		
		
		
	}


	private String filePath;

	public String getFilePath() {
		filePath = AssetModifyActivity.this.getFilesDir().getAbsoluteFile() + File.separator + AssetConstants.PANDIAN_TMPFILE_NAME;
		return filePath;
	}
}
